package com.example.demo3.controller;

import com.example.demo3.entity.User;
import com.example.demo3.service.RedisService;
import com.example.demo3.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("user")
public class UserController {

    @Autowired
    private UserService userService;

    @Autowired
    private RedisService redisService;

    @GetMapping("/queryById")
    public String queryById(Integer id){
        String userStr = redisService.get(id +"");
        if (userStr != null){
            redisService.set(id +"",userService.queryById(id).toString());
        }
        return userStr;
    }

//    //TODO 增删改查
//    @RequestMapping
//    public User add() {
//        User user = new User();
//        user.setId(1);
//        user.setAge(20);
//        user.setName("小明");
//        userService.save(user);
//        return user;
//    }
//    @RequestMapping
//    public void delete(){
//      userService.deletUserById(1);
//
//    }

}
